<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>transition</title>

  <style>
    .box1 {
      width: 100px;
      height: 100px;
      /* background: red; */
      position: relative;
      left: 0;
      top: 0;
      transition: opacity 1s, height 1s;
      animation: 2s rainbow infinite alternate;
    }

    .box1:hover {
      opacity: 0.5;
      height: 200px;
    }


    @keyframes rainbow {
      0% {
        background: yellow;
      }

      100% {
        background: blue;
      }
    }
  </style>
</head>

<body>


  <div class="box1"></div>
</body>

</html>